package cn.kgc.util;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class Page implements Serializable {
	private int pageIndex;
	private int totalCount;
	private int size=20;
	private int totalPage;
	private List list;
	public int getPageIndex() {
		return pageIndex;
	}
	public void setPageIndex(int pageIndex) {
		if(pageIndex<1){
			pageIndex=1;
		}
		this.pageIndex = pageIndex;
	}
	public void setPageIndex(String pageIndexStr) {
		if(pageIndexStr==null){//非空判断
			pageIndexStr="1";
		}
		int pageIndex=Integer.parseInt(pageIndexStr);
		if(pageIndex<1){
			pageIndex=1;
		}
		this.pageIndex = pageIndex;
	}

	public int getTotalCount() {
		return totalCount;
	}
	public void setTotalCount(int totalCount) {
		//计算总页数
		totalPage=totalCount%size==0?totalCount/size:totalCount/size+1;
		//判断页码上限
		if(pageIndex>totalPage){
			pageIndex=totalPage;
		}
		this.totalCount = totalCount;
	}
	public int getSize() {
		return size;
	}
	public void setSize(int size) {
		this.size = size;
	}
	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}
	public List getList() {
		return list;
	}
	public void setList(List list) {
		this.list = list;
	}

	public List<Integer> getPageNumbers(int count){
		int begin=(pageIndex-1)/count*count+1;
		List<Integer> list=new ArrayList<Integer>();
		for(int i=0;i<count;i++){
			if(begin+i>totalPage){
				break;
			}
			list.add(begin+i);
		}
		return list;
	}

}